<?php
	header('content-type:text/html;charset=utf-8'); 
	$light_pass_number = $_POST["light_pass_number"];//光通量
	$voltage = $_POST["voltage"];//电压
	$color_area = $_POST["color_area"];//色区
	$bin_code = $_POST["bin_code"];//bincode
	$xianzhi = $_POST["xianzhi"];//显指
	$dianliu = $_POST["dianliu"];//电流
	$LSM = $_POST["LSM"];//流水码
	$order_id = $_POST["order_id"];//工单号
	$CPXH = $_POST["CPXH"];//产品型号
	$number = $_POST["number"];//数量
	$time = $_POST["time"];//时间
	$pdo =new pdo("mysql:host=127.0.0.1;port=3306;dbname=tddb;","root","tdled2018");
	$pdo->query("set character set 'utf8'");//读库 
	$pdo->query("set names 'utf8'");//写库 
	$allnumber=0;
	$finishnumber=0;
	$lsm="";
	
		$sql1="
			SELECT 
				mom_orderdetail.Qty
			FROM 
				mom_orderdetail 
			inner join 
				mom_order
			on 
				mom_orderdetail.MoId=mom_order.MoId
			where 
				MoCode='".$order_id."'
			";
		$res1=$pdo->prepare($sql1);//准备查询语句 
		$res1->execute(); //执行一条查询语句 
		while ($row = $res1->fetch()){
			//$i+=1;
			$allnumber=$row['Qty'];
		}
		$sql2=
			"
			SELECT 
				finishnumber
			FROM 
				bpirecord 
			WHERE 
				order_id='".$order_id."'
			ORDER BY 
				finishnumber 
			DESC 
			LIMIT 1
		";
		$res2=$pdo->prepare($sql2);//准备查询语句 
		$res2->execute(); //执行一条查询语句 
		while ($row = $res2->fetch()){
			//$i+=1;
			$finishnumber=$row['finishnumber']+$number;
		}
		
		$sql = "
			INSERT INTO 
				`bpirecord`
				(
				`light_pass_number`, 
				`voltage`, 
				`color_area`, 
				`bin_code`, 
				`xianzhi`,
				`dianliu`, 
				`LSM`, 
				`order_id`, 
				`CPXH`, 
				`number`,
				`finishnumber`,
				`time`) 
			VALUES (
				'".$light_pass_number."',
				'".$voltage."',
				'".$color_area."',
				'".$bin_code."',
				'".$xianzhi."',
				'".$dianliu."',
				'".$LSM."',
				'".$order_id."',
				'".$CPXH."',
				'".$number."',
				'".$finishnumber."',
				'".$time."'
			)";
		$res=$pdo->prepare($sql);//准备查询语句 
		$res->execute(); //执行一条查询语句
		echo $pdo->lastInsertId()."-".$allnumber."-".$finishnumber."-"."存入成功";
	
	
?>